package com.oa.controller;

import com.oa.pojo.Duty;
import com.oa.pojo.Result;
import com.oa.pojo.Role;
import com.oa.pojo.RoleMenu;
import com.oa.service.RoleMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "角色-菜单中间表：在线接口")
@RestController
@RequestMapping("/rm")
public class RoleMenuController {

    @Autowired
    private RoleMenuService roleMenuService;

    @CrossOrigin
    @ApiOperation(value="查询角色菜单中间表(id,roleId，menuId)",httpMethod = "GET",notes = "返回包含用户类的result类型json格式")
    @GetMapping("/selectAll")
    public Result selectAll(Integer id,Integer roleId,Integer menuId){
        System.out.println("执行查询角色菜单接口");

        List<RoleMenu> roleMenuList = roleMenuService.selectRoleMenu(id,roleId,menuId);

        if (roleMenuList!=null) {
            return Result.success(roleMenuList);
        }else {
            return Result.success();
        }
    }
    @CrossOrigin
    @ApiOperation(value="根据角色菜单中间表的id删除(id)",httpMethod = "GET",notes = "返回包含用户类的result类型json格式")
    @GetMapping("/deleteRoleMenu")
    public Result deleteRoleMenu(Integer id){
        System.out.println("执行删除角色菜单中间表功能");

        int flag= roleMenuService.deleteRoleMenu(id);
        if (flag==1){
            return Result.success();
        }else {
            return Result.error("没有id为"+id+"的角色菜单中间表");

        }
    }

    @CrossOrigin
    @ApiOperation(value="角色菜单中间表信息更改",httpMethod = "POST",notes = "返回的result类型json格式")
    @PostMapping("/updateRoleMenu")
    public Result updateRoleMenu(@RequestBody RoleMenu roleMenu){
        System.out.println("执行角色菜单中间表信息更改功能");

        int flag= roleMenuService.updateRoleMenu(roleMenu);
        if (flag==1) {
            return Result.success();
        }else {
            return Result.error("添加心部门失败，有重复属性");
        }
    }

    @CrossOrigin
    @ApiOperation(value="添加角色菜单中间表",httpMethod = "POST",notes = "返回的result类型json格式")
    @PostMapping("/insertRoleMenu")
    public Result insertRoleMenu(@RequestBody RoleMenu roleMenu){
        System.out.println("执行角色菜单添加接口");

        int flag=roleMenuService.insertRoleMenu(roleMenu);

        if (flag==1) {
            return Result.success();
        }else {
            return Result.error("添加心部门失败，有重复属性");
        }
    }
}
